ALTER VIEW [dbo].[View_FW_User]
AS
SELECT
         fu.UserGUID,
         fu.UserCode,
         fu.UserName,
         fu.UserEmail,
         fu.UserOfficePhone,
         fu.UserMobilePhone,
         fu.UserHomePhone,
		 fu.UserIsAdmin,
         fu.UserADAccount,
         fu.UserIsDisabeld,
         fu.UserDisabledReason,
         fu.UserJobNumber,
         fu.IsUserChangePWD,
         fu.UserIsLocked,
         fu.UserLockTime,
         fu.PUserosition,
         fu.IsFormalEstablishment,
         fu.LastIpAdress,
         fu.UserImageUrl,
         fu.UserPreImageUrl,
         fu.LoginErrorCount,
         fu.LastLoginErrorTime,
         fu.PasswordModifyTime,
         fu.LoginTime,
         fu.TenantId,
         fu.IsDeleted,
         fu.CreateTime,
         fu.CreateGUID,
         fu.CreatedName,
         fu.ModifiedTime,
         fu.ModifiedGUID,
         fu.ModifiedName,
         fu.ApproveState,
         fu.ApproveGUID,
         fu.ApproveTime,
         fu.BuUnitGUID,
         fu.UserIntID,
		 fu.BuUnitNewGUIDs,
		 fu.IsMainAccountUser,
		 fu.TokenExpiryMinute,
		 fu.TokenRoles,
		 fu.DefaultBuUnitGUID,
		 fu.DefaultApplicationGUID,
		LOWER(STUFF(( SELECT  ',' + CAST(StandardRoleGUID AS VARCHAR(36))
		                 FROM   dbo.FW_StandardRole2USer
		                 WHERE   UserGUID = fu.UserGUID
		               FOR
		                 XML PATH('')
		               ), 1, 1, '')) AS StandardRoleGUIDs,

		fbu.CompanyGUID AS DefaultCompanyGUID
FROM dbo.FW_User fu
LEFT JOIN dbo.FW_BuUnit fbu ON fbu.BuUnitNewGUID=fu.DefaultBuUnitGUID